﻿/**
* Font selector plugin
* turns an ordinary input field into a list of web-safe fonts
* Usage: $('select').fontSelector();
*
* Author     : James Carmichael
* Website    : www.siteclick.co.uk
* License    : MIT
*/
jQuery.fn.fontSelector = function (b) {

    var fonts = new Array('Arial,Arial,Helvetica,sans-serif',
'Arial Black,Arial Black,Gadget,sans-serif',
'BleedingCowboys',
'Cantarell',
'Capture it',
'Comic Sans MS,Comic Sans MS,cursive',
'Courier New,Courier New,Courier,monospace',
'Daniel',
'Days',
'DroidSans',
'Flux Architect',
'Georgia,Georgia,serif',
'GoodDog',
'Impact,Charcoal,sans-serif',
'Impact Label',
'Journal',
'KatyBerry',
'Kingthings',
'Lilly',
'Lucida Console,Monaco,monospace',
'Lucida Sans Unicode,Lucida Grande,sans-serif',
'Palatino Linotype,Book Antiqua,Palatino,serif',
'Marketing Script',
'NeoRetroDraw',
'Quicksand',
'Snickles',
'Susie',
'Tahoma,Geneva,sans-serif',
'Times New Roman,Times,serif',
'Trebuchet MS,Helvetica,sans-serif',
'Verdana,Geneva,sans-serif',
'Windsong',
'Xpressive');

    return this.each(function () {

        // Get input field
        var sel = this;

        // Add a ul to hold fonts
        var ul = $('<ul class="fontselector"></ul>');
        $('body').prepend(ul);
        $(ul).hide();


        jQuery.each(fonts, function (i, item) {

            $(ul).append('<li><a href="#" class="font_' + i + '" style="font-family: ' + item + '">' + item.split(',')[0] + '</a></li>');

            // Prevent real select from working
            $(sel).focus(function (ev) {

                ev.preventDefault();

                // Show font list
                $(ul).show();

                // Position font list
                $(ul).css({ top: $(sel).offset().top + $(sel).height() + 4,
                    left: $(sel).offset().left
                });

                // Blur field
                $(this).blur();


                return false;
            });

            $(sel).click(function (ev) {
                ev.stopPropagation();
            });

            $(ul).find('a').click(function () {
                var font = fonts[$(this).attr('class').split('_')[1]];
                $(sel).val(font.split(',')[0]);
                $(sel).css("font-family", font);
                $(ul).hide();
                // change nameFont
                if (b == 0) {
                    $("#dNameSurname").css("font-family", font);
                    save("nameFont", font);
                }
                // change titleFont
                if (b == 1) {
                    $("#dTitle").css("font-family", font);
                    save("titleFont", font);
                }
                // change shortDescFont
                if (b == 2) {
                    $("#dDescription").css("font-family", font);
                    save("shortDescFont", font);
                }
                return false;
            });


            $(document).click(function () {
                $(ul).hide();
            });


        });


    });

}